const ResSuccess = (res,fun)=>{
  if (!res.error_code){
    typeof fun === "function" && fun(true,res.data);
  }else{
    typeof fun === "function" && fun(false,res);    
  }
}

const ResFail = () => {
  wx.showToast({
    title: "网络异常 ~",
    icon:"none",
    mask:true
  });
}

const HOST = "https://www.ljl03.cn";
// const HOST = "https://jx.wufenhuyu.com";
export const URL = {
  uploadingImg: HOST+"/AipImageClassify.php"
};

export const GET = (url, params, fun)=>{
  wx.request({
    url: url,
    method: "GET",
    data: params,
    dataType: "json",
    header: { "content-type": "application/x-www-form-urlencoded" },
    success(res) {
      ResSuccess(res,fun);
    },
    fail(){
      ResFail();
    }
  }); 

}

export const POST = (url, params, fun) => {
  wx.request({
    url: url,
    method: "POST",
    data: params,
    dataType: "json",
    header: { "content-type": "application/x-www-form-urlencoded" },
    success(res) {
      ResSuccess(res, fun);
    },
    fail() {
      ResFail();
    }
  });

}